package com.java;

public class ObjectAPI {
    static class Student implements Cloneable {
        private String name = "SYX";
        private Integer age = 19;
        
        public Student() {}
        
        @Override
        public String toString() {
            return this.name + this.age;
        }
        
        @Override
        protected Object clone() throws CloneNotSupportedException {
            return super.clone();
        }
    }
    
    public static void main(String[] args) throws CloneNotSupportedException {
        // toString：将对象转为String，默认为`this.getClass().getName()+"@"+Integer.toHexString(this.hashCode())`
        System.out.println(new Student().toString()); // SYX19
        
        // getClass：获取Xxx.class运行时类
        System.out.println(new Student().getClass()); // class com.java.ObjectAPI$Student
        
        // equals：判断对象是否相同。默认比较地址值，重写后一般比较属性值
        System.out.println(new Student().equals(new Student())); // false
        
        // hashCode：获取对象的哈希值。哈希值表示对象存于哈希表的索引，哈希值与地址值有关
        System.out.println(new Student().hashCode()); // 460141958
        
        // clone：克隆原对象成新对象。该函数是受保护的不能直接使用，实现Cloneable接口并重写Object中的clone后可使用
        Student student = new Student();
        System.out.println(student == student.clone()); // false
    }
}
